<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>1.指定centos的IP | 张先生的文档</title>
    <meta name="generator" content="VuePress 1.9.9">
    <link rel="icon" href="zhang.jpeg">
    <meta name="description" content="张先生的文档网页">
    
    <link rel="preload" href="/vue-press/assets/css/0.styles.a2a0458e.css" as="style"><link rel="preload" href="/vue-press/assets/js/app.5f50dbcf.js" as="script"><link rel="preload" href="/vue-press/assets/js/2.733019b2.js" as="script"><link rel="preload" href="/vue-press/assets/js/8.75c8c290.js" as="script"><link rel="prefetch" href="/vue-press/assets/js/3.bea23741.js"><link rel="prefetch" href="/vue-press/assets/js/4.d12742be.js"><link rel="prefetch" href="/vue-press/assets/js/5.216cae74.js"><link rel="prefetch" href="/vue-press/assets/js/6.2d0a63f8.js"><link rel="prefetch" href="/vue-press/assets/js/7.3bd2328a.js">
    <link rel="stylesheet" href="/vue-press/assets/css/0.styles.a2a0458e.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/vue-press/" class="home-link router-link-active"><img src="/vue-press/zhang.jpeg" alt="张先生的文档" class="logo"> <span class="site-name can-hide">张先生的文档</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/vue-press/" class="nav-link">
  Home
</a></div><div class="nav-item"><a href="https://www.baidu.com" target="_blank" rel="noopener noreferrer" class="nav-link external">
  百度
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><a href="https://blog.csdn.net" target="_blank" rel="noopener noreferrer" class="nav-link external">
  CSDN
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><a href="/vue-press/blog/fontend/" class="nav-link">
  前端
</a></div><div class="nav-item"><a href="/vue-press/blog/backend/" class="nav-link">
  后端
</a></div><div class="nav-item"><a href="/vue-press/guide/guide.html" class="nav-link">
  导航
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Language Menu" class="dropdown-title"><span class="title">语言</span> <span class="arrow down"></span></button> <button type="button" aria-label="Language Menu" class="mobile-dropdown-title"><span class="title">语言</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/vue-press/language/chinese/" class="nav-link">
  中文
</a></li><li class="dropdown-item"><!----> <a href="/vue-press/language/english/" class="nav-link">
  英文
</a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/vue-press/" class="nav-link">
  Home
</a></div><div class="nav-item"><a href="https://www.baidu.com" target="_blank" rel="noopener noreferrer" class="nav-link external">
  百度
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><a href="https://blog.csdn.net" target="_blank" rel="noopener noreferrer" class="nav-link external">
  CSDN
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><a href="/vue-press/blog/fontend/" class="nav-link">
  前端
</a></div><div class="nav-item"><a href="/vue-press/blog/backend/" class="nav-link">
  后端
</a></div><div class="nav-item"><a href="/vue-press/guide/guide.html" class="nav-link">
  导航
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Language Menu" class="dropdown-title"><span class="title">语言</span> <span class="arrow down"></span></button> <button type="button" aria-label="Language Menu" class="mobile-dropdown-title"><span class="title">语言</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/vue-press/language/chinese/" class="nav-link">
  中文
</a></li><li class="dropdown-item"><!----> <a href="/vue-press/language/english/" class="nav-link">
  英文
</a></li></ul></div></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>1.指定centos的IP</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/vue-press/VirtualConfig.html#_1-指定centos的ip" class="sidebar-link">1.指定centos的IP</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/vue-press/VirtualConfig.html#_2-编辑配置文件-设置ip" class="sidebar-link">2.编辑配置文件，设置IP</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/vue-press/VirtualConfig.html#_3-重新启动network" class="sidebar-link">3.重新启动network</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/vue-press/VirtualConfig.html#_4-要上网还需要配置dns" class="sidebar-link">4.要上网还需要配置DNS</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/vue-press/VirtualConfig.html#_5-关闭centos的防火墙" class="sidebar-link">5.关闭centos的防火墙</a><ul class="sidebar-sub-headers"></ul></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h2 id="_1-指定centos的ip"><a href="#_1-指定centos的ip" class="header-anchor">#</a> 1.指定centos的IP</h2> <p>首先登陆centos7修改network的配置文件</p> <div class="language- extra-class"><pre class="language-text"><code>cd /etc/sysconfig/network-scripts/
</code></pre></div><h2 id="_2-编辑配置文件-设置ip"><a href="#_2-编辑配置文件-设置ip" class="header-anchor">#</a> 2.编辑配置文件，设置IP</h2> <div class="language-javascript extra-class"><pre class="language-javascript"><code>cd到根路径编辑
vi ifcfg<span class="token operator">-</span>enp0s3
相对路径直接编辑
vi <span class="token operator">/</span>etc<span class="token operator">/</span>sysconfig<span class="token operator">/</span>network<span class="token operator">-</span>scripts<span class="token operator">/</span>ifcfg<span class="token operator">-</span>enp0s3
</code></pre></div><p><img src="img/ip%E9%85%8D%E7%BD%AE.png" alt=""></p> <div class="language- extra-class"><pre class="language-text"><code>TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static //改static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=enp0s3
UUID=0be6716f-53b6-4ad9-8350-aad192bda16d
DEVICE=enp0s3
ONBOOT=yes //改yes
IPADDR=172.16.1.155 //自定义虚拟机ip
NETMASK=255.255.255.0 //字掩码
GATEWAY=172.16.1.1 //默认网关
DNS1=114.114.114.114 //首选DNS服务器，不设置则无法联网。
DNS2=114.114.115.115 //备用DNS服务器。
114是电信做的国内免费公众DNS服务器，也是最受大众所周知的DNS服务器。解析成功率较高，而且速度相稳定，是国内用户上网使用比较多的DNS地址。
</code></pre></div><h2 id="_3-重新启动network"><a href="#_3-重新启动network" class="header-anchor">#</a> <strong>3.重新启动network</strong></h2> <div class="language- extra-class"><pre class="language-text"><code>service network restart
</code></pre></div><h2 id="_4-要上网还需要配置dns"><a href="#_4-要上网还需要配置dns" class="header-anchor">#</a> 4.要上网还需要配置DNS</h2> <p>编辑resolv.conf</p> <div class="language- extra-class"><pre class="language-text"><code>vi /etc/resolv.conf 
</code></pre></div><p><img src="img/%E7%BC%96%E8%BE%91resolv.png" alt=""></p> <p>在里面添加如下两条服务器地址：</p> <div class="language- extra-class"><pre class="language-text"><code>nameserver 114.114.114.114 
nameserver 114.114.115.115
</code></pre></div><p>配置完成后， 测试一下网络的连通性</p> <div class="language- extra-class"><pre class="language-text"><code>ping www.baidu.com
</code></pre></div><p><img src="img/%E6%B5%8B%E8%AF%95%E7%BD%91%E7%BB%9C.png" alt=""></p> <h2 id="_5-关闭centos的防火墙"><a href="#_5-关闭centos的防火墙" class="header-anchor">#</a> 5.关闭centos的防火墙</h2> <div class="language- extra-class"><pre class="language-text"><code>systemctl stop firewalld.service

1、开启防火墙
systemctl start firewalld
2、开放指定端口
firewall-cmd --zone=public --add-port=6379/tcp --permanent
命令含义：
–zone #作用域
–add-port=6379/tcp #添加端口，格式为：端口/通讯协议
–permanent #永久生效，没有此参数重启后失效
3、重启防火墙
firewall-cmd --reload
4、查看端口号
netstat -ntlp //查看当前所有tcp端口·
netstat -ntulp |grep 6379 //查看所有1935端口使用情况·

1.查看所有已经对外开放的端口：
firewall-cmd --list-ports
2.移除开放端口
firewall-cmd --zone=public --remove-port=8899/tcp --permanent
3.重启防火墙
firewall-cmd --reload
</code></pre></div></div> <footer class="page-edit"><!----> <!----></footer> <!----> </main></div><div class="global-ui"></div></div>
    <script src="/vue-press/assets/js/app.5f50dbcf.js" defer></script><script src="/vue-press/assets/js/2.733019b2.js" defer></script><script src="/vue-press/assets/js/8.75c8c290.js" defer></script>
  </body>
</html>
